package main

import (
	"log"
	"net/http"

	"gee/day4-group/gee"
)

func main() {
	r := gee.New()

	r.GET("/html", func(c *gee.Context) {
		c.HTML(http.StatusOK, "<h1> wuhu qifei <h1>")
	})

	v1 := r.Group("/v1")
	{
		v1.POST("/json", func(c *gee.Context) {
			c.JSON(http.StatusOK, gee.H{
				"username": "wuhuwuhuwuhuwuhu",
				"password": "qifeiqifei",
			})
		})

		v1.GET("/string", func(c *gee.Context) {
			for k, v := range c.R.Header {
				c.String(http.StatusOK, "Header[%q]= %q\n", k, v)
			}
		})
	}

	v2 := r.Group("/v2")
	{
		v2.GET("/hello/:name", func(c *gee.Context) {
			// expect /hello/geektutu
			c.String(http.StatusOK, "hello %s, you're at %s\n", c.Param("name"), c.Path)
		})

		v2.POST("/login", func(c *gee.Context) {
			c.R.ParseForm()
			c.JSON(http.StatusOK, gee.H{
				"username": c.PostForm("username"),
				"password": c.PostForm("password"),
			})
		})
	}

	if err := r.Run(":8080"); err != nil {
		log.Fatal(err)
	}
}
